package com.template.tool.ajax;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletResponse;

public class Flush{
	
	public static void flush(StringBuffer xml,HttpServletResponse response){
		System.out.println(xml);
		String s=xml.toString();
		s=s.replaceAll("&", "&amp;");
		response.setContentType("text/xml;charset=UTF-8");
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.write("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+s);
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				out = null;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
	
	public static void flushText(StringBuffer xml,HttpServletResponse response){
		response.setContentType("text/plain;charset=UTF-8");
		System.out.println(xml);
		String s=xml.toString();	
		PrintWriter out = null;
		try {
			out = response.getWriter();
			out.write(s);
			out.flush();
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				out = null;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
